using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using yq.IBase;
using yq.Dictionary;
using yq.Basis;
using yq.Model.Logic;
using System.Collections;
using Db;
using System.Data.Common;

namespace yq.Model.Base
{
    ///<summary>
    /// File_Ver - 文件版本控制 - 对象基础类
    /// </summary>
    ///<typeparam name="T"></typeparam>
    public abstract class IFileVer<T> : ModelBase<FileVer> where T : FileVer, new()
    {
        /// <summary>
        /// 写入主键值
        /// </summary>
        /// <param name="Id">主键</param>
        protected internal override void SetKeyValue(dynamic Id)
        {
            this.VerId = Id;
        }

        /// <summary>
        /// 获取主键值
        /// </summary>
        /// <returns></returns>
        protected internal override dynamic GetKeyValue()
        {
            return VerId;
        }

        /// <summary>
        /// 为本对象赋值
        /// </summary>
        /// <param name="dy"></param>
        public override void SetValue(dynamic dy)
        {
            this.VerId = dy.VerId;
            this.FileId = dy.FileId;
            this.FileInfoId = dy.FileInfoId;
            this.CheckInTime = dy.CheckInTime;
            this.CheckInUserId = dy.CheckInUserId;
            this.IsCurrent = dy.IsCurrent;
            this.Detailed = dy.Detailed;
            this.Version = dy.Version;
        }

        #region 定义属性


        /// <summary>
        /// 版本ID
        /// </summary>
        private String _VerId = "";

        /// <summary>
        /// 版本ID
        /// </summary>
        public String VerId
        {
            get
            {
                return (this._VerId);
            }

            set
            {
                _VerId = value;
            }
        }


        /// <summary>
        /// 文件ID
        /// </summary>
        private String _FileId = "";

        /// <summary>
        /// 文件ID
        /// </summary>
        public String FileId
        {
            get
            {
                return (this._FileId);
            }

            set
            {
                _FileId = value;
            }
        }


        /// <summary>
        /// 文件信息ID
        /// </summary>
        private String _FileInfoId = "";

        /// <summary>
        /// 文件信息ID
        /// </summary>
        public String FileInfoId
        {
            get
            {
                return (this._FileInfoId);
            }

            set
            {
                _FileInfoId = value;
            }
        }


        /// <summary>
        /// 签入时间
        /// </summary>
        private DateTime _CheckInTime = DateTime.MinValue;

        /// <summary>
        /// 签入时间
        /// </summary>
        public DateTime CheckInTime
        {
            get
            {
                return (this._CheckInTime);
            }

            set
            {
                _CheckInTime = value;
            }
        }


        /// <summary>
        /// 签入用户ID
        /// </summary>
        private String _CheckInUserId = "";

        /// <summary>
        /// 签入用户ID
        /// </summary>
        public String CheckInUserId
        {
            get
            {
                return (this._CheckInUserId);
            }

            set
            {
                _CheckInUserId = value;
            }
        }


        /// <summary>
        /// 是否当前版本
        /// </summary>
        private int _IsCurrent = -1;

        /// <summary>
        /// 是否当前版本
        /// </summary>
        public yq.Enums.BooleanType IsCurrent
        {
            get
            {
                return (yq.Enums.BooleanType)_IsCurrent;
            }

            set
            {
                _IsCurrent = value.GetHashCode();
            }
        }


        /// <summary>
        /// 说明
        /// </summary>
        private String _Detailed = "";

        /// <summary>
        /// 说明
        /// </summary>
        public String Detailed
        {
            get
            {
                return (this._Detailed);
            }

            set
            {
                _Detailed = value;
            }
        }


        #endregion 定义属性

        protected internal override void SetValue(FileVer info, DataRow row)
        {
            if (row == null)
            {
                info.IsLoad = false;
            }
            else
            {
                info.IsLoad = true;

                if (row["VerId"] != DBNull.Value)
                {
                    info.VerId = row["VerId"].ToString();
                }


                if (row["FileId"] != DBNull.Value)
                {
                    info.FileId = row["FileId"].ToString();
                }


                if (row["FileInfoId"] != DBNull.Value)
                {
                    info.FileInfoId = row["FileInfoId"].ToString();
                }


                if (row["CheckInTime"] != DBNull.Value)
                {
                    info.CheckInTime = Convert.ToDateTime(row["CheckInTime"]);
                }


                if (row["CheckInUserId"] != DBNull.Value)
                {
                    info.CheckInUserId = row["CheckInUserId"].ToString();
                }


                if (row["IsCurrent"] != DBNull.Value)
                {
                    info.IsCurrent = (yq.Enums.BooleanType)(row["IsCurrent"]);
                }


                if (row["Detailed"] != DBNull.Value)
                {
                    info.Detailed = row["Detailed"].ToString();
                }


                if (row["Version"] != DBNull.Value)
                {
                    info.Version = row["Version"].ToString();
                }

            }

        }

        protected internal override void GetDbParameters(DbCommand comm, FileVer info, DbHelper cn)
        {

            cn.AddInParameter(comm, "@VerId", DbType.String, ParameterTool.GetObj(info._VerId));


            cn.AddInParameter(comm, "@FileId", DbType.String, ParameterTool.GetObj(info._FileId));


            cn.AddInParameter(comm, "@FileInfoId", DbType.String, ParameterTool.GetObj(info._FileInfoId));


            cn.AddInParameter(comm, "@CheckInTime", DbType.DateTime, ParameterTool.GetObj(info._CheckInTime));


            cn.AddInParameter(comm, "@CheckInUserId", DbType.String, ParameterTool.GetObj(info._CheckInUserId));


            cn.AddInParameter(comm, "@IsCurrent", DbType.Int32, ParameterTool.GetObj(info._IsCurrent));


            cn.AddInParameter(comm, "@Detailed", DbType.String, ParameterTool.GetObj(info._Detailed));


            cn.AddInParameter(comm, "@Version", DbType.String, Guid.NewGuid().ToString());


            cn.AddInParameter(comm, "@_versionOdl", DbType.String, info._Version);

        }

    }
}